package com.cx.service.impl;

import com.cx.mapper.CarMapper;
import com.cx.pojo.Car;
import com.cx.pojo.CarInfoModel;
import com.cx.service.CarService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CarServiceImpl implements CarService{
    @Autowired
    CarMapper carMapper;

    //添加汽车
    @Override
    public int insert(Car car) {
        return carMapper.insert(car);
    }

    //修改汽车
    @Override
    public int updateByPrimaryKey(Car car) {
        return carMapper.updateByPrimaryKey(car);
    }

    //根据id删除汽车
    @Override
    public int deleteByPrimaryKey(Integer carId) {
        return carMapper.deleteByPrimaryKey(carId);
    }

    //根据id查询汽车
    @Override
    public Car selectByPrimaryKey(Integer carId) {
        return carMapper.selectByPrimaryKey(carId);
    }

    //查询所有汽车
    @Override
    public List<CarInfoModel> selectAllCar(CarInfoModel carInfoModel) {;
        return carMapper.selectAllCar(carInfoModel);
    }

    //分页
    public PageInfo<CarInfoModel> CarManage(CarInfoModel carInfoModel) {
        PageHelper.startPage(carInfoModel.getPageNum(), carInfoModel.getPageSize());
        List<CarInfoModel> carInfoModels = carMapper.selectAllCar(carInfoModel);
        return new PageInfo<>(carInfoModels);
    }
}
